<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ExifTool Date/Time Shift Module</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@osx219.apple.com" />
</head>

<body style="background-color: white">
<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="_podblock_" style="background-color: #cccccc" valign="middle">
<big><strong><span class="_podblock_">&nbsp;ExifTool Date/Time Shift Module</span></strong></big>
</td></tr>
</table>



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="#METHODS">METHODS</a>
    <ul>
      <li><a href="#ShiftTime">ShiftTime</a></li>
    </ul>
  </li>
  <li><a href="#SHIFT-STRING">SHIFT STRING</a></li>
  <li><a href="#NOTES">NOTES</a></li>
  <li><a href="#TRICKY">TRICKY</a></li>
  <li><a href="#BUGS">BUGS</a></li>
  <li><a href="#AUTHOR">AUTHOR</a></li>
  <li><a href="#SEE-ALSO">SEE ALSO</a></li>
</ul>

<h1 id="NAME">NAME</h1>

<p>Image::ExifTool::Shift.pl - ExifTool time shifting routines</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module contains routines used by ExifTool to shift date and time values.</p>

<h1 id="METHODS">METHODS</h1>

<h2 id="ShiftTime">ShiftTime</h2>

<p>Shift date/time value</p>

<pre><code>    use Image::ExifTool;
    $err = Image::ExifTool::ShiftTime($dateTime, $shift);</code></pre>

<dl>

<dt id="Inputs">Inputs:</dt>
<dd>

<p>0) Date/time string in EXIF format (eg. <code>2016:01:30 11:45:00</code>).</p>

<p>1) Shift string (see below) with optional leading sign for shift direction.</p>

<p>2) [optional] Direction of shift (-1 or +1), or 0 or undef to use the sign from the shift string.</p>

<p>3) [optional] Reference to time-shift hash -- filled in by first call to <b>ShiftTime</b>, and used in subsequent calls to shift date/time values by the same relative amount (see <a href="#TRICKY">&quot;TRICKY&quot;</a> section below).</p>

<p>or</p>

<p>0) Shift string (and $_ contains the input date/time string).</p>

</dd>
<dt id="Return-value">Return value:</dt>
<dd>

<p>Error string, or undef on success and the input date/time string is shifted by the specified amount.</p>

</dd>
</dl>

<h1 id="SHIFT-STRING">SHIFT STRING</h1>

<p>Time shifts are applied to standard EXIF-formatted date/time values (eg. <code>2005:03:14 18:55:00</code>). Date-only and time-only values may also be shifted, and an optional timezone (eg. <code>-05:00</code>) is also supported. Here are some general rules and examples to explain how shift strings are interpreted:</p>

<p>Date-only values are shifted using the following formats:</p>

<pre><code>    &#39;Y:M:D&#39;     - shift date by &#39;Y&#39; years, &#39;M&#39; months and &#39;D&#39; days
    &#39;M:D&#39;       - shift months and days only
    &#39;D&#39;         - shift specified number of days</code></pre>

<p>Time-only values are shifted using the following formats:</p>

<pre><code>    &#39;h:m:s&#39;     - shift time by &#39;h&#39; hours, &#39;m&#39; minutes and &#39;s&#39; seconds
    &#39;h:m&#39;       - shift hours and minutes only
    &#39;h&#39;         - shift specified number of hours</code></pre>

<p>Timezone shifts are specified in the following formats:</p>

<pre><code>    &#39;+h:m&#39;      - shift timezone by &#39;h&#39; hours and &#39;m&#39; minutes
    &#39;-h:m&#39;      - negative shift of timezone hours and minutes
    &#39;+h&#39;        - shift timezone hours only
    &#39;-h&#39;        - negative shift of timezone hours only</code></pre>

<p>A valid shift value consists of one or two arguments, separated by a space. If only one is provided, it is assumed to be a time shift when applied to a time-only or a date/time value, or a date shift when applied to a date-only value. For example:</p>

<pre><code>    &#39;1&#39;         - shift by 1 hour if applied to a time or date/time
                  value, or by one day if applied to a date value
    &#39;2:0&#39;       - shift 2 hours (time, date/time), or 2 months (date)
    &#39;5:0:0&#39;     - shift 5 hours (time, date/time), or 5 years (date)
    &#39;0:0:1&#39;     - shift 1 s (time, date/time), or 1 day (date)</code></pre>

<p>If two arguments are given, the date shift is first, followed by the time shift:</p>

<pre><code>    &#39;3:0:0 0&#39;         - shift date by 3 years
    &#39;0 15:30&#39;         - shift time by 15 hours and 30 minutes
    &#39;1:0:0 0:0:0+5:0&#39; - shift date by 1 year and timezone by 5 hours</code></pre>

<p>A date shift is simply ignored if applied to a time value or visa versa.</p>

<p>Numbers specified in shift fields may contain a decimal point:</p>

<pre><code>    &#39;1.5&#39;       - 1 hour 30 minutes (time, date/time), or 1 day (date)
    &#39;2.5 0&#39;     - 2 days 12 hours (date/time), 12 hours (time) or
                  2 days (date)</code></pre>

<p>And to save typing, a zero is assumed for any missing numbers:</p>

<pre><code>    &#39;1::&#39;       - shift by 1 hour (time, date/time) or 1 year (date)
    &#39;26:: 0&#39;    - shift date by 26 years
    &#39;+:30&#39;      - shift timezone by 30 minutes</code></pre>

<p>Below are some specific examples applied to real date and/or time values (&#39;Dir&#39; is the applied shift direction: &#39;+&#39; is positive, &#39;-&#39; is negative):</p>

<pre><code>     Original Value         Shift   Dir    Shifted Value
    ---------------------  -------  ---  ---------------------
    &#39;20:30:00&#39;             &#39;5&#39;       +   &#39;01:30:00&#39;
    &#39;2005:01:27&#39;           &#39;5&#39;       +   &#39;2005:02:01&#39;
    &#39;2005:01:27 20:30:00&#39;  &#39;5&#39;       +   &#39;2005:01:28 01:30:00&#39;
    &#39;11:54:00&#39;             &#39;2.5 0&#39;   -   &#39;23:54:00&#39;
    &#39;2005:11:02&#39;           &#39;2.5 0&#39;   -   &#39;2005:10:31&#39;
    &#39;2005:11:02 11:54:00&#39;  &#39;2.5 0&#39;   -   &#39;2005:10:30 23:54:00&#39;
    &#39;2004:02:28 08:00:00&#39;  &#39;1 1.3&#39;   +   &#39;2004:02:29 09:18:00&#39;
    &#39;07:00:00&#39;             &#39;-5&#39;      +   &#39;07:00:00&#39;
    &#39;07:00:00+01:00&#39;       &#39;-5&#39;      +   &#39;07:00:00-04:00&#39;
    &#39;07:00:00Z&#39;            &#39;+2:30&#39;   -   &#39;07:00:00-02:30&#39;
    &#39;1970:01:01&#39;           &#39;35::&#39;    +   &#39;2005:01:01&#39;
    &#39;2005:01:01&#39;           &#39;400&#39;     +   &#39;2006:02:05&#39;
    &#39;10:00:00.00&#39;          &#39;::1.33&#39;  -   &#39;09:59:58.67&#39;</code></pre>

<h1 id="NOTES">NOTES</h1>

<p>The format of the original date/time value is not changed when the time shift is applied. This means that the length of the date/time string will not change, and only the numbers in the string will be modified. The only exception to this rule is that a &#39;Z&#39; timezone is changed to &#39;+00:00&#39; notation if a timezone shift is applied. A timezone will not be added to the date/time string.</p>

<h1 id="TRICKY">TRICKY</h1>

<p>This module is perhaps more complicated than it needs to be because it is designed to be very flexible in the way time shifts are specified and applied...</p>

<p>The ability to shift dates by Y years, M months, etc, conflicts with the design goal of maintaining a constant shift for all time values when applying a batch shift. This is because shifting by 1 month can be equivalent to anything from 28 to 31 days, and 1 year can be 365 or 366 days, depending on the starting date.</p>

<p>The inconsistency is handled by shifting the first tag found with the actual specified shift, then calculating the equivalent time difference in seconds for this shift and applying this difference to subsequent tags in a batch conversion. So if it works as designed, the behaviour should be both intuitive and mathematically correct, and the user shouldn&#39;t have to worry about details such as this (in keeping with Perl&#39;s &quot;do the right thing&quot; philosophy).</p>

<h1 id="BUGS">BUGS</h1>

<p>Due to the use of the standard time library functions, dates are typically limited to the range 1970 to 2038 on 32-bit systems.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Copyright 2003-2024, Phil Harvey (philharvey66 at gmail.com)</p>

<p>This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p><a>Image::ExifTool(3pm)</a></p>

<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="_podblock_" style="background-color: #cccccc" valign="middle">
<big><strong><span class="_podblock_">&nbsp;ExifTool Date/Time Shift Module</span></strong></big>
</td></tr>
</table>

</body>

</html>


